<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/fn"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>

<%-- Creates a form label. Parameters are :
    - code : required, the code for the label.
    - id : optional, the ID of the form element to reference.
    - usePartialValue : optional, boolean string value, 'true' if the related label info box
      must display a label notifying the user that he can use partial values.
    - mandatory : optional, boolean string value, 'true' if the field is mandatory.
    - infoMsgArgs : the arguments for the info message on the label.
    - javaScriptEscape : whether the info message should be javascript escaped.
 --%>

<c:set var="codePrefix" value=""/>
<c:set var="labelCodePrefix" value="${codePrefix}"/>
<c:set var="infoCodePrefix" value="${codePrefix}"/>

<c:set var="javascriptEscape" value="true"/>

<c:if test="${not empty param.javaScriptEscape}">
  <c:set var="javascriptEscape" value="${param.javaScriptEscape}"/>
</c:if>

<spring:theme var="infoMsg" code="${infoCodePrefix}${param.code}"
  javaScriptEscape="${javascriptEscape}" arguments="${param.infoMsgArgs}" htmlEscape="false"/>
<c:set var="labelId" value="label_${fn:replace(param.code, '.', '')}"/>
<c:set var="displayInfo" value="${not empty infoMsg || param.usePartialValue == 'true'}"/>

<%-- Computing the info box messages to display --%>
<c:if test="${displayInfo}">
  <c:if test="${param.usePartialValue == 'true'}">
    <spring:theme var="partialValueLabel"
      code="search.form.partial.values.accepted"
      javaScriptEscape="true"/>
  </c:if>
</c:if>

<%-- Computing the class for the label --%>
<c:if test="${displayInfo}">
  <c:set var="labelClass" value="info"/>
</c:if>
<c:if test="${param.mandatory == 'true'}">
  <c:set var="labelClass" value="${labelClass} mandatory"/>
</c:if>

<%-- The label --%>
<label id="${labelId}" class="${labelClass}"
  <c:if test="${displayInfo}">
    onmouseover="javascript:showLabelInfoBox('${labelId}', '${infoMsg}', '${partialValueLabel}');"
    onmouseout="javascript:hideLabelInfoBox();"
  </c:if>>
  <spring:theme code="${labelCodePrefix}${param.code}"/>
</label>


